package me.shurufa.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.holder.BaseViewHolder;
import me.shurufa.widget.EllipsizingTextView;
import me.shurufa.widget.likebutton.LikeButton;

/**
 * 作者 : andy
 * 日期 : 16/3/8 14:50
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 横向主题列表适配器
 */
public class ShareThemeAdapter extends RecyclerView.Adapter<ShareThemeAdapter.ThemeHolder> {

    private List<String> names;
    private List<String> colors;
    private OnThemeSelectListener mListener;

    public ShareThemeAdapter() {
        names = new ArrayList<>();
        colors = new ArrayList<>();

        names.add("黄色");
        names.add("粉色");
        names.add("蓝色");
        names.add("绿色");
        names.add("白色");

        colors.add("#ed7861");
        colors.add("#f6dbdb");
        colors.add("#79b3e4");
        colors.add("#90b06e");
        colors.add("#e0e0e0");
    }

    @Override
    public ThemeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_theme, parent, false);
        return new ThemeHolder(v);
    }

    @Override
    public int getItemCount() {
        return names.size();
    }

    @Override
    public void onBindViewHolder(final ThemeHolder holder, final int position) {
        holder.iv_bg.setBackgroundColor(Color.parseColor(colors.get(position)));
        holder.tv_theme_name.setText(names.get(position));

        holder.iv_bg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onThemeSelected(colors.get(position));
                }
            }
        });
    }

    public class ThemeHolder extends BaseViewHolder {

        @Bind(R.id.iv_bg)
        ImageView iv_bg;
        @Bind(R.id.tv_theme_name)
        TextView tv_theme_name;

        public ThemeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }

    public void setOnThemeSelectListener(OnThemeSelectListener l) {
        this.mListener = l;
    }

    public interface OnThemeSelectListener {
        void onThemeSelected(String color);
    }

}
